<?php

function getOrderCount($uid, $status)
{
    return \app\common\model\Order::where(['uid' => $uid, 'status' => $status])->count();
}

function getProductOrderFriendly($value)
{
    return match ($value) {
        1 => '商品待付款',
        2 => '商品已付款，等待卖家发货',
        3 => '商家已发货，等待确认收货',
        4 => '交易已完成',
        default => ''
    };
}

function substrCut($userName)
{
    if (!$userName) return '未绑定';
    $strlen = mb_strlen($userName, 'utf-8');
    $firstStr = mb_substr($userName, 0, 1, 'utf-8');
    $lastStr = mb_substr($userName, -1, 1, 'utf-8');
    $resultName = ($strlen == 2) ? $firstStr . str_repeat('*', mb_strlen($userName, 'utf-8') - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;

    return $resultName;
}


function strreplace($str, $startlen = 0, $endlen = 4)
{
    if (!$str) return '未绑定';
    $repstr = "";
    if (strlen($str) < ($startlen + $endlen + 1)) {
        return $str;
    }
    $count = strlen($str) - $startlen - $endlen;
    for ($i = 0; $i < $count; $i++) {
        $repstr .= "*";
    }
    return preg_replace('/(\d{' . $startlen . '})\d+(\d{' . $endlen . '})/', '${1}' . $repstr . '${2}', $str);
}
